home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / nextgo23.taz / nextgo23 / NeXTGo / opening.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  1.3 KB  |  58 lines

  1. #include "comment.header"
  2.  
  3. extern int rd, MAXX, MAXY;
  4. extern void Random(int*);
  5.  
  6. int opening(int *i, int *j, int *cnd, int type)
  7.      /* get move for opening from game tree */
  8. {
  9.   struct tnode {
  10.     int i, j, ndct, next[8];
  11.   };
  12.   
  13.   static struct tnode tree[] = {
  14.     {-1, -1, 8, { 1, 2, 3, 4, 5, 6, 7, 20}},    /* 0 */
  15.     {2, 3, 2, { 8, 9}},
  16.     {2, 4, 1, {10}},
  17.     {3, 2, 2, {11, 12}},
  18.     {3, 3, 6, {14, 15, 16, 17, 18, 19}},
  19.     {3, 4, 1, {10}},  /* 5 */
  20.     {4, 2, 1, {13}},
  21.     {4, 3, 1, {13}},
  22.     {4, 2, 0},
  23.     {4, 3, 0},
  24.     {3, 2, 0},  /* 10 */
  25.     {2, 4, 0},
  26.     {3, 4, 0},
  27.     {2, 3, 0},
  28.     {2, 5, 1, {10}},
  29.     {2, 6, 1, {10}},  /* 15 */
  30.     {3, 5, 1, {10}},
  31.     {5, 2, 1, {13}},
  32.     {5, 3, 1, {13}},
  33.     {6, 2, 1, {13}},
  34.     {2, 2, 0}  /* 20 */
  35.   };
  36.   int m;
  37.   
  38.   /* get i, j */
  39.   if ((type == 1) || (type == 3))
  40.     *i = (18 - tree[*cnd].i)*MAXX/19;   /* inverted */
  41.   else
  42.     *i = tree[*cnd].i*MAXX/19;
  43.   if ((type == 2) || (type == 3))
  44.     *j = (18 - tree[*cnd].j)*MAXY/19;   /* reflected */
  45.   else
  46.     *j = tree[*cnd].j*MAXY/19;
  47.   if (tree[*cnd].ndct)  /* more move */
  48.     {
  49.       Random(&rd);
  50.       m = rd % tree[*cnd].ndct;  /* select move */
  51.       *cnd = tree[*cnd].next[m];    /* new    current node */
  52.       return 1;
  53.     }
  54.   else
  55.     return 0;
  56. }  /* end opening */
  57.  
  58.